package com.xpgk.common.constants;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.kit.StrKit;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class ConstantsParam {

	private static final Log log = Log.getLog(ConstantsParam.class);

	public static Map<String, Record> jxb = new HashMap<>();

	public static Map<String, Record> kfb = new HashMap<>();

	public static Map<Integer, Record> kcb = new HashMap<>();

	public static Map<Integer, Record> cdjk = new HashMap<>();

	// public static Map<String, Record> k2xm = new HashMap<>();

	// public static Map<String, Record> k3xm = new HashMap<>();

	public static Record xtsz = null;

	public static void init() {

		String jxb_sql = "SELECT * FROM DRIVE_JXB";
		List<Record> jxbs = Db.find(jxb_sql);
		if (jxbs.size() > 0) {
			for (Record jx : jxbs) {
				jxb.put(jx.getStr("JXDM"), jx);
			}
			log.info("初始化 驾校表");
		} else {
			log.info("驾校表 为空");
		}

		String kfb_sql = "SELECT * FROM DRIVE_KFB";
		List<Record> kfbs = Db.find(kfb_sql);
		if (kfbs.size() > 0) {
			for (Record kf : kfbs) {
				kfb.put(kf.getStr("KFDM"), kf);
				if (kf.getInt("KSKM") == 2 && kf.getInt("TYPE") == 2) {
					// k2xm.put(kf.getStr("KFDM"), kf);
				}
				if (kf.getInt("KSKM") == 3 && kf.getInt("TYPE") == 2) {
					// k3xm.put(kf.getStr("KFDM"), kf);
				}
			}
			log.info("初始化 扣分表");
		} else {
			log.info("扣分表 为空");
		}

		String kcb_sql = "SELECT * FROM DRIVE_KCB ORDER BY ID";
		List<Record> kcbs = Db.find(kcb_sql);
		if (kcbs.size() > 0) {
			for (Record kc : kcbs) {
				kcb.put(kc.getInt("ID"), kc);
			}
			log.info("初始化 考车表");
		} else {
			log.info("考车表 为空");
		}

		String sql = "SELECT * FROM DRIVE_CDJK";
		List<Record> ksxms = Db.find(sql);
		if (ksxms.size() > 0) {
			for (Record ksxm : ksxms) {
				if (StrKit.notBlank(ksxm.getStr("XMH"))) {
					cdjk.put(Integer.parseInt(ksxm.getStr("XMH")), ksxm);
				}
			}
			log.info("初始化 场地监控表");
		} else {
			log.info("场地监控表 为空");
		}

		String xtsz_sql = "SELECT * FROM DRIVE_XTSZ where id = 1";
		xtsz = Db.findFirst(xtsz_sql);
		if (null == xtsz) {
			log.info("系统设置表 为空");
		} else {
			log.info("初始化 系统设置表");
		}
	}
}
